<?php
include 'header.php';


$user = $_SESSION['user'];

$tasks = $snsdb->get_results("select * from sns_rss_task where uid=".$user->id);

?>

        <script type="text/javascript">
			function opreatetask(id, status){
				var target = jQuery(window.event.srcElement);
				
				if(target.attr('class') == 'zhuangtai'){
					$.ajax({
	                	type: 'POST',
	                	url: 'opreatetask.php',
	                	data: {'id': id, 'op':'ss', 'status': 2},
	                	success: function(data){
	                		target.attr('class','kaishi');
		                	target.html('已停止');
	                    	}
	                	});
				}

				if(target.attr('class') == 'kaishi'){
					$.ajax({
	                	type: 'POST',
	                	url: 'opreatetask.php',
	                	data: {'id': id, 'op':'ss', 'status': 1},
	                	success: function(data){
	                		target.attr('class','zhuangtai');
		                	target.html('正在运行');
	                    	}
	                	});
				}
			} 

			function deletetask(id){
				var target = jQuery(window.event.srcElement);
				$.ajax({
                	type: 'POST',
                	url: 'opreatetask.php',
                	data: {'id': id, 'op':'de'},
                	success: function(data){
                		target.parent().parent().remove();
                    	}
                	});
			}       
        </script>
            	
                <div id="sider_left">
                	<img src="images/b_sider_top.jpg" width="207" height="7" class="imgfloat" />
                    	<ul>
                        	<li id="weixuan"><a href="myacounts.php">我的账号</a></li>
                            <li id="xuanzhong">我的任务</li>
                        </ul>
                    <img src="images/b_sider_buttom.jpg" width="207" height="7" class="imgfloat" />
                </div>
                <div id="sider_right">
                	<img src="images/sider_righttop.jpg" width="642" height="6" class="imgfloat" />
                    	<div id="sr_top">
                        	<span id="allrw">所有任务列表</span>
                            <span id="addnew"><a href="addtask.php">添加新任务</a></span>
                            <div id="rwcont">
                            <?php foreach ($tasks as $key=>$task){
                            ?>
                            	<ul>
                                	<li class="rwtitile"><?php echo $key+1;?>.&nbsp;&nbsp;<a href="addtask.php?action=edit&id=<?php echo $task->id;?>" title="点击编辑任务" ><?php echo $task->title;?></a></li>
                                	<?php if($task->status == 1){?>
                                	<li onclick="opreatetask('<?php echo $task->id;?>', <?php echo $task->status;?>)"  class="zhuangtai" title="点击停止任务">正在运行</li>
                                	<?php }else if ($task->status == 2){?>
                                	<li onclick="opreatetask('<?php echo $task->id;?>', <?php echo $task->status;?>)"  class="kaishi" title="点击开始任务">已停止</li>
                                	<?php }else if($task->status ==3){?>
                                	<li  class="kaishi" title="等待后台调度该任务">等待执行</li>
                                	<?php }else if($task->status == 4){?>
                                	<li class="errorstate" title="该任务的调度信息出错，请重新编辑该任务">任务出错</li>
                                	<?php }?>
                                   
                                    <li class="delete">&nbsp;<a href="javascript:void(0)" onclick="deletetask('<?php echo $task->id;?>')">删除</a></li>
                                </ul>
                             <?php }?>
                            </div>
                        </div>
                    <img src="images/sider_rightbuttom.jpg" width="642" class="imgfloat" />
                </div>
        	<img src="images/container_buttom.gif" width="880" height="12" class="imgfloat" />
        </div>
    </body>
</html>
